package ru.compscicenter.uno.view.animation;

import ru.compscicenter.uno.view.CardImage;

/**
 * Created by IntelliJ IDEA.
 * User: Павел
 * Date: 10.12.11
 * Time: 2:23
 * To change this template use File | Settings | File Templates.
 */
public class SimpleCardTransferAnimation {
	private final int x1, y1, w1, h1;
	private final int x2, y2, w2, h2;
	private final long startTime;
	private final int dx, dy, dw, dh, dt;

	public SimpleCardTransferAnimation(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2, long startTime, long maxTime) {
		this.x1 = x1;
		this.y1 = y1;
		this.w1 = w1;
		this.h1 = h1;
		this.x2 = x2;
		this.y2 = y2;
		this.w2 = w2;
		this.h2 = h2;
		this.startTime = startTime;
		dx = x2 - x1;
		dy = y2 - y1;
		dw = w2 - w1;
		dh = h2 - h1;
		dt = (int) (maxTime - startTime);
	}

	public int getX(int timeAfterStart) {
		if (isFinished(timeAfterStart)) {
			return x2;
		}
		return x1 + dx * timeAfterStart / dt;
	}

	public int getY(int timeAfterStart) {
		if (isFinished(timeAfterStart)) {
			return y2;
		}
		return y1 + dy * timeAfterStart / dt;
	}

	public int getW(int timeAfterStart) {
		if (isFinished(timeAfterStart)) {
			return w2;
		}
		return w1 + dw * timeAfterStart / dt;
	}

	public int getH(int timeAfterStart) {
		if (isFinished(timeAfterStart)) {
			return h2;
		}
		return h1 + dh * timeAfterStart / dt;
	}

	public boolean isFinished(int timeAfterStart) {
		return timeAfterStart >= dt;
	}

	public long getStartTime() {
		return startTime;
	}
}
